<meta args="rowList"/>
<div s="loop" id="rows" s-data="rowList">
    <div s-loop-role="row" s="row" class="floor-row">
        <div class="m-b row-window" s="window"></div>
    </div>
</div>
<div class="">
    <a href="javascript:;" class="btn btn-default btn-xs"
       s-click="addRow()">
        <i class="fa fa-plus"></i> 新增行
    </a>
</div>
<script>
    $rows.node.sortable({
        handle: ".rows-sort-handle"
    })

    function remove($this) {
        $this.node.parentsUntil(".floor-row").parent().remove();
    }

    function addRow() {
        $rows.addRows([{
            showcaseList: []
        }]).done(function () {
            loadShowcasePanel();
        });
    }

    function loadShowcasePanel() {
        S.N(".row-window").each(function () {
            var node = $(this);
            if (node.attr("showcase-loaded")) {
                return;
            }
            node.attr("showcase-loaded", true);
            var $node = Smart.of(node);
            var $row = $node.parent();
            var data = $row.data();
            $node.load("/operation-center/IndexFloorSetting-row.html", {data: data})
        })
    }

    S.on("s-ready", function () {
        loadShowcasePanel();
    })

    S.getContent = function() {
        var rowList = [];
        $rows.node.find(".floor-row").each(function () {
            var node = $(this);
            var $row = Smart.of(node);
            var $rowPanel = Smart.of($row.node.find(".row-window"))
            rowList.push($rowPanel.getContent());
        })
        return rowList
    }
</script>